package com.compass.mobile.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.compass.mobile.databinding.LayoutItemCommonBinding
import com.compass.mobile.framework.adapter.BaseBindViewHolder
import com.compass.mobile.framework.adapter.BaseRecyclerViewAdapter
import com.compass.mobile.models.Dictionaries
import com.compass.mobile.R

/**
 * Description：
 * Date:2024/7/12 14:14
 */
class SuggestAdapter : BaseRecyclerViewAdapter<Dictionaries, LayoutItemCommonBinding>() {


    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): LayoutItemCommonBinding {
        return LayoutItemCommonBinding.inflate(layoutInflater, parent, false)
    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<LayoutItemCommonBinding>,
        item: Dictionaries?,
        position: Int
    ) {
        if (item == null) return
        holder.binding.apply {
            tvName.text = item.label
        }
        holder.binding.tvName.onFocusChangeListener = View.OnFocusChangeListener { v, hasFocus ->
            // 在这里处理焦点变化的逻辑
            if (hasFocus) {
                holder.binding.tvName.setBackgroundResource(R.drawable.bg_shape_yellow_5)
            } else {
                // 当 EditText 失去焦点时的操作
                if(item.isSelect)  holder.binding.tvName.setBackgroundResource(R.drawable.bg_shape_suggest_select) else holder.binding.tvName.setBackgroundResource(R.drawable.bg_common)
            }
        }
        if(item.isSelect)  holder.binding.tvName.setBackgroundResource(R.drawable.bg_shape_suggest_select) else holder.binding.tvName.setBackgroundResource(R.drawable.bg_common)
    }
}
